package com.kkb.shopcenter.server.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kkb.shopcenter.api.MemberInfoService;
import com.kkb.shopcenter.common.pojo.MemberInfo;
import com.kkb.shopcenter.server.mappers.MemberInfoMapper;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class MemberInfoServiceImpl implements MemberInfoService {

    @Autowired
    private MemberInfoMapper memberInfoMapper;

    @Override
    public PageInfo<MemberInfo> getMemberList(Integer page, Integer pageSize, Integer level, String memberName) {
        PageHelper.startPage(page,pageSize);
        Example example = new Example(MemberInfo.class);
        if(level!=null&&level>0){
            example.createCriteria().andEqualTo("level",level);
        }
        if(StringUtils.isNotEmpty(memberName)){
            example.createCriteria().andLike("memberName",memberName);
        }

        List<MemberInfo> memberInfos = memberInfoMapper.selectByExample(example);
        PageInfo<MemberInfo> pageInfo = new PageInfo<>(memberInfos);
        return pageInfo;
    }

    @Override
    public int editMember(MemberInfo memberInfo) {

        return memberInfoMapper.updateByPrimaryKeySelective(memberInfo);
    }

    @Override
    public int deleteMember(Long id) {
        return memberInfoMapper.deleteByPrimaryKey(id);
    }
}
